/*
 * noodle.c
 *
 *  Created on: 2017年4月11日
 *      Author: zhikang.peng
 */

#include "system-api.h"
#include <stdio.h>

void HariMain(void) {
	char *buf, s[12];
	int win, timer, sec = 0, min = 0, hour = 0;

	api_initmalloc();
	buf = api_malloc(150 * 50);
	win = api_openwindos(buf, 150, 50, -1, "noodle");
	timer = api_allocTimer();
	api_initTimer(timer, 128);
	for (;;) {
		sprintf(s, "%5d:%02d:%02d", hour, min, sec);
		api_boxwindosfill(win, 28, 27, 115, 41, 7);
		api_putwindostext(win, 28, 27, 0, 11, s);

		api_setTimer(timer, 100); // 1s
		if (api_getKeyboardData(1) != 128) {
			break;
		}
		sec++;
		if (sec == 60) {
			sec = 0;
			min++;
			if (min == 60) {
				min = 0;
				hour++;
			}
		}
	}
	api_end();
}
